package com.spring.springboot.sys.core.config;

import io.jsonwebtoken.lang.Assert;
import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * @author 宋义州
 * @date 2022-07-23  11:42
 * @description 配置参数
 */
@Data
@Component
@ConfigurationProperties(ignoreInvalidFields = true, prefix = "jwt")
public class SecurityConfigProperties implements InitializingBean {

    /**
     * jwt 密钥
     */
    private String secret;

    /**
     * jwt 有效期（单位 秒）
     */
    private Long expiration;

    /**
     * 请求头token名称
     */
    private String header = "Authorization";

    /**
     * token 内容前缀
     */
    private String prefix = "Bearer ";

    @Override
    public void afterPropertiesSet() {
        Assert.hasText(this.secret, "jwt-secret must be set");
        Assert.notNull(this.expiration, "jwt-expiration-ms must be set");
        Assert.notNull(this.header, "jwt-token-name must be set");
        Assert.notNull(this.prefix, "jwt-token-prefix must be set");
    }
}
